package com.adtec.base.cloud.comminicate.communicate.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenAPIConfig {

  @Bean
  public GroupedOpenApi commonlyusedApi() {
    return GroupedOpenApi.builder()
            .group("01-常用网址")
            .pathsToMatch("/commonlyused/**")
            .build();
  }

  @Bean
  public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components()
                    .addSecuritySchemes("loginHeader", new SecurityScheme()
                            .type(SecurityScheme.Type.APIKEY)
                            .in(SecurityScheme.In.HEADER)
                            .name("userId")))
            .addSecurityItem(new SecurityRequirement().addList("loginHeader"));
  }
}
